﻿Namespace mnsrulz

    Public Class mSongsController
        Inherits System.Web.Mvc.Controller



        Private Shared Sub DoProcess(ByVal initID As Integer)
            '''''http://www.apunkabollywood.net/browser/download/get/1808'''
            Dim i As Integer = initID
            Dim wc As New System.Net.WebClient
            Do
                Try
                    'If Not songsIDCollection.Contains(i) Then
                    Dim songURL = String.Format("http://208.78.41.223/browser/download/get/{0}", i)
                    Dim data = wc.DownloadString(songURL)
                    Dim o = mSongsModels.SongModel.Transform(data)
                    If o IsNot Nothing Then
                        o.ID = i
                        mSongsModels.SongService.InsertSong(o)
                        'o.PageURL = songURL
                        'SyncLock lstSongs
                        '    SaveSong(o)
                        '    lstSongs.Add(o)
                        'End SyncLock
                    Else
                        Throw New Exception("data not found for songurl : " & songURL)
                    End If
                    'End If
                Catch ex As Exception
                    'WriteError(ex.Message)
                    If i > 70000 Then
                        System.Threading.Thread.Sleep(60000)
                    End If
                Finally
                    i += 1
                End Try
            Loop
        End Sub

        Shared Sub New()
            Dim th As New Threading.Thread(AddressOf DoProcess)
            Dim initid = mSongsModels.SongService.GetLastFMWSongInserted()
            th.Start(initid)
        End Sub

        '
        ' GET: /mSongs

        Function Index() As ActionResult
            Return View()
        End Function


        Function Albums(Optional ByVal from As Integer = 1) As ActionResult
            Dim o = mnsrulz.mSongsModels.AlbumService.ListAlbums
            ViewData("list") = o
            Return View()
        End Function

        Function Album(ByVal albumId As Integer) As ActionResult
            Dim o = mSongsModels.AlbumService.GetAlbumByID(albumId)
            Return View(o)
        End Function

        Function Songs(ByVal startRow As Integer, ByVal maxRows As Integer) As ActionResult
            Return View()
        End Function

        '<HttpGet()> _
        'Function Songs(ByVal id As Integer) As ActionResult
        '    Return View()
        'End Function

        '<HttpPost()> _
        'Function Songs(ByVal id As Integer) As ActionResult
        '    Return View()
        'End Function

        '<HttpGet()> _
        'Function Songs(ByVal id As Integer, ByVal name As String) As ActionResult
        '    Return View()
        'End Function
    End Class
End Namespace